package lxt.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import lxt.action.core.ActionSupport;
import lxt.entity.InvoiceOrder;
import lxt.service.InvoiceInfoService;
import lxt.service.InvoiceOrderService;
/**
 * 派单action
 * @author Lit
 *
 */
public class InvoiceInfoAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	/**
	 * 定义变量
	 */
	private String orderId;
	private String truckId;
	/**
	 * 定义接口
	 */
	private InvoiceInfoService invoiceInfoService;
	private InvoiceOrderService invoiceOrderService;
	/**
	 * 定义返回集
	 */
	private List<Object> object;
	//定义分页变量
	private Integer pageCounts = 10; //每页显示数量
	private String currPageStr = "1"; //分页
	private Integer totalCounts ;//总数据量
	
	/**
	 * 加载派单信息
	 * @return
	 */
	public String loadAll(){
		try {
			//定义从第几条显示
			int offset =( Integer.parseInt(currPageStr)-1)*pageCounts;
			object = this.invoiceInfoService.queryDistribute(orderId,truckId,offset,pageCounts);
			totalCounts = (Integer) object.get(object.size()-1);
			object.remove(object.size()-1);
		} catch (Exception ex) {
			ex.printStackTrace();
			this.addActionMessage("操作失败，请检查重新操作");
		}
		return SUCCESS;
	}
	/**
	 * 派发 
	 */
	public String distribute(){
		try {
			InvoiceOrder invo = this.invoiceOrderService.loadInvoiceOrderById(orderId);
			Date date = new Date();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			String temp = sdf.format(date);
			invo.setSTime(sdf.parse(temp));
			this.invoiceOrderService.updateInvoiceOrder(invo, "PaiFa", null, null, null, null, null);
		} catch (Exception ex) {
			ex.printStackTrace();
			this.addActionMessage("操作失败，请检查重新操作");
		}
		return SUCCESS;
	}
	/**
	 * get set
	 * @return
	 */
	public InvoiceInfoService getInvoiceInfoService() {
		return invoiceInfoService;
	}
	public void setInvoiceInfoService(InvoiceInfoService invoiceInfoService) {
		this.invoiceInfoService = invoiceInfoService;
	}
	public List<Object> getObject() {
		return object;
	}
	public void setObject(List<Object> object) {
		this.object = object;
	}
	public String getOrderId() {
		return orderId;
	}
	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}
	public InvoiceOrderService getInvoiceOrderService() {
		return invoiceOrderService;
	}
	public void setInvoiceOrderService(InvoiceOrderService invoiceOrderService) {
		this.invoiceOrderService = invoiceOrderService;
	}
	public String getTruckId() {
		return truckId;
	}
	public void setTruckId(String truckId) {
		this.truckId = truckId;
	}
	public Integer getPageCounts() {
		return pageCounts;
	}
	public void setPageCounts(Integer pageCounts) {
		this.pageCounts = pageCounts;
	}
	public String getCurrPageStr() {
		return currPageStr;
	}
	public void setCurrPageStr(String currPageStr) {
		this.currPageStr = currPageStr;
	}
	public Integer getTotalCounts() {
		return totalCounts;
	}
	public void setTotalCounts(Integer totalCounts) {
		this.totalCounts = totalCounts;
	}
}
